import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { ArticleVO, ArticleForm, ArticleQuery } from '@/api/blog/article/types';

/**
 * 查询博客文章列表
 * @param query
 * @returns {*}
 */

export const listArticle = (query?: ArticleQuery): AxiosPromise<ArticleVO[]> => {
  return request({
    url: '/blog/article/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询博客文章详细
 * @param articleId
 */
export const getArticle = (articleId: string | number): AxiosPromise<ArticleVO> => {
  return request({
    url: '/blog/article/' + articleId,
    method: 'get'
  });
};

/**
 * 新增博客文章
 * @param data
 */
export const addArticle = (data: ArticleForm) => {
  return request({
    url: '/blog/article',
    method: 'post',
    data: data
  });
};

/**
 * 修改博客文章
 * @param data
 */
export const updateArticle = (data: ArticleForm) => {
  return request({
    url: '/blog/article',
    method: 'put',
    data: data
  });
};

/**
 * 删除博客文章
 * @param articleId
 */
export const delArticle = (articleId: string | number | Array<string | number>) => {
  return request({
    url: '/blog/article/' + articleId,
    method: 'delete'
  });
};
